<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	class Product_model extends CI_Model{
		//TODO lägg över retrieve_prducts hit sen
		
		function list_categories()
		{
			$query = $this->db->get("products_category");
			if($query->num_rows() > 0)
			{
				return $query->result_array();
			}
			return false;
		}
		
		function get_product(){
			$id = $this->uri->segment(3,0);
			//$query = $this->db->get_where("products", array("id" => $id));
			
			$this->db->select('*');
			$this->db->from('products');
			$this->db->join('products_category', 'products_category.categoryId = products.categoryId');
			$this->db->where("id", $id);
			$query = $this->db->get();
			
			if($query->num_rows() > 0)
			{
				return $query->row();
			}
			return false;
		}
		
		function retrive_products_by_id(){
			
			$id = $this->uri->segment(3,0);
			$query = $this->db->get_where("products", array("categoryId" => $id));
        	return $query->result_array();
		}
		
		function retrive_category()
		{
			$id = $this->uri->segment(3,0);
			$query = $this->db->get_where("products_category", array("categoryId" => $id));
			return $query->row();
		}
	}